<?php

namespace app\models;

/**
 * This is the model class for table "integral_record".
 *
 * @property int $id
 * @property int $member_id
 * @property int $good_id
 * @property int $good_integral
 * @property int $record_status 0 未领取 1 已领取
 * @property string $check_code
 * @property int $update_time
 * @property int $create_time
 */
class IntegralRecord extends \yii\db\ActiveRecord {
  /**
   * {@inheritdoc}
   */
  public static function tableName()
  {
    return 'integral_record';
  }

  /**
   * {@inheritdoc}
   */
  public function rules()
  {
    return [
        [['member_id', 'good_id', 'good_integral', 'check_code', 'update_time', 'create_time'], 'required'],
        [['member_id', 'good_id', 'good_integral', 'record_status', 'update_time', 'create_time'], 'integer'],
        [['check_code'], 'string', 'max' => 32],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function attributeLabels()
  {
    return [
        'id'            => 'ID',
        'member_id'     => 'Member ID',
        'good_id'       => 'Good ID',
        'good_integral' => 'Good Integral',
        'record_status' => 'Record Status',
        'check_code'    => 'Check Code',
        'update_time'   => 'Update Time',
        'create_time'   => 'Create Time',
    ];
  }

  public static function getNoExchange($id)
  {
    $record_count = IntegralRecord::find()->where(['member_id' => $id, 'record_status' => 0])->count();
    return $record_count;
  }
}
